import { FC, ReactNode } from 'react';

import { BoxRealtimeInfo } from './BatteryBox';
import { BoxTotalRealtimeInfo } from './BatteryBoxTotal';
import { ClusterRealtimeInfo } from './BatteryCluster';
import { ModuleRealtimeInfo } from './BatteryModule/RealtimeInfo';
import { StackRealtimeInfo } from './BatteryStack';

import { ElectricMeter } from './ElectricMeter';
import ElectricMeterTotal from './ElectricMeterTotal/index';
import { GLC } from './GLC';
import { GLCTotal } from './GLCTotal';
import { LC } from './LC';

import { Pcs } from './PCS';
import { PCSTotal } from './PCSTotal';

import { PCSController } from './PCSController';
import { PCSControllerTotal } from './PCSControllerTotal';
import { Transformer } from './Transformer';
import { TransformerTotal } from './TransformerTotal';

import { Inverter } from './Inverter';
import { InverterTotal } from './InverterTotal';

import { ChangePile } from './ChangePile';
import { ChangePileTotal } from './ChangePileTotal';

import { EMMU } from './EMMU';
import { useSelectedDeviceNode } from './SelectedDeviceNodeContext';
import { StationRealtimeInfo } from './Station';
import { SubareaRealtimeInfo } from './Subarea';

export const RealtimeInfo: FC = () => {
  const node = useSelectedDeviceNode();
  const type =
    node?.deviceName === 'EMMU' ? node?.deviceName : node?.deviceType ?? node?.deviceType;
  console.log(type, '相应的类型');
  //电表 电池箱 一体柜  pc控制器 最顶层树节点
  const isGroup = node?.nodeType === 'DEVICE_GROUP';
  let renderContent: ReactNode = null;
  switch (type) {
    // station
    case 'STATION':
    case 'ROOT':
      renderContent = <StationRealtimeInfo />;
      break;
    case 'AREA':
      renderContent = <SubareaRealtimeInfo />;
      break;
    case 'BOX':
    case 'CABINET':
      // renderContent = <EMMU />;
      if (isGroup) {
        renderContent = <BoxTotalRealtimeInfo />;
      } else {
        renderContent = <BoxRealtimeInfo />;
      }
      break;
    case 'STACK':
    case 'BMS':
      renderContent = <StackRealtimeInfo />;
      break;
    case 'CLUSTER':
      renderContent = <ClusterRealtimeInfo />;
      break;
    case 'MODULE':
    case 'BMU':
      renderContent = <ModuleRealtimeInfo />;
      break;
    case 'PCS':
      if (isGroup) {
        renderContent = <PCSTotal />;
      } else {
        renderContent = <Pcs />;
      }
      break;
    //这个是pcs控制器相关的
    case 'PCS_CONT':
      if (isGroup) {
        renderContent = <PCSControllerTotal />;
      } else {
        renderContent = <PCSController />;
      }
      break;
    //电表维度
    case 'METER':
      if (isGroup) {
        renderContent = <ElectricMeterTotal />;
      } else {
        renderContent = <ElectricMeter />;
      }
      break;
    case 'GLC':
      if (isGroup) {
        renderContent = <GLCTotal />;
      } else {
        renderContent = <GLC />;
      }
      break;
    case 'LC':
      renderContent = <LC />;
      break;
    case 'TRANSFORMER':
      if (isGroup) {
        renderContent = <TransformerTotal />;
      } else {
        renderContent = <Transformer />;
      }
      break;
    case 'INVERTER':
      if (isGroup) {
        renderContent = <InverterTotal />;
      } else {
        renderContent = <Inverter />;
      }
      break;
    case 'CHARGE_PILE':
      if (isGroup) {
        renderContent = <ChangePileTotal />;
      } else {
        renderContent = <ChangePile />;
      }
      break;
    case 'EMMU':
      renderContent = <EMMU isGrgrounp={true} />;
      break;
    case 'DEHUMIDITY':
      renderContent = <EMMU isGrgrounp={false} ShowDEHUMIDIT={true} />;
      break;
    case 'LIQUID_COOL':
      renderContent = <EMMU isGrgrounp={false} ShowLIQUID_COOL={true} />;
      break;
    case 'AIR_COOL':
      renderContent = <EMMU isGrgrounp={false} ShowAIR_COOL={true} />;
      break;
    case 'FIRE_HOST':
      renderContent = <EMMU isGrgrounp={false} ShowFIRE_HOST={true} />;
      break;
    case 'FIRE_DETECTOR':
      renderContent = <EMMU isGrgrounp={false} ShowFIRE_DETECTOR={true} />;
      break;
    case 'LEAK_DETECTOR':
      renderContent = <EMMU isGrgrounp={false} ShowLEAK_DETECTOR={true} />;
      break;

    default:
      break;
  }

  return renderContent;
};
